#include "linkdescription.h"
#include "ui_linkdescription.h"

LinkDescription::LinkDescription(int index, QWidget *parent) :
    QFrame(parent),
    ui(new Ui::LinkDescription)
{
    ui->setupUi(this);
    this->index=index;

    ui->seqLayout->setText(QString().number(index)+":");
}

LinkDescription::~LinkDescription()
{
    delete ui;
}

void LinkDescription::setUrl(QString url){
    ui->addressLayout->setText(url);
};
void LinkDescription::setProxy(int p){
    this->proxy=p;
    if(proxy==-1){
        ui->proxyLabel->setText("");
    }else{
        ui->proxyLabel->setText("Using: "+QString().number(proxy));
    }
};
void LinkDescription::setState(int state){
    switch(state){
    case FREE:
        ui->statusLayout->setText("FREE");
        break;
    case INUSE:
        ui->statusLayout->setText("PREPAREING");
        break;
    case DOWNLOADING_FILE:
        ui->statusLayout->setText("DOWNLOADING");
        break;
    case WAIT:
        ui->statusLayout->setText("WAITING");
        break;
    case FINISHED:
        ui->statusLayout->setText("FINNISHED");
        break;
    case ERR_DELETED:
        ui->statusLayout->setText("FILE DELETED");
        break;
    case ERR_UNKNOWN_PAGE:
        ui->statusLayout->setText("UNNOWN PAGE");
        break;
    case ERR_SOCKET_ERROR:
        ui->statusLayout->setText("SOCKET ERROR");
        break;
    case ERR_UNKNOWN_PROVIDER:
        ui->statusLayout->setText("UNKNOWN PROVIDER");
        break;
    default:
        ui->statusLayout->setText(QString().number(state));
    }
};
void LinkDescription::setProgress(int prog){
    ui->progressBar->setValue(prog);
};
void LinkDescription::setSpeed(int speed){
    ui->speedLayout->setText(QString().number(speed/1024)+" kB/s");
};
